package service

import (
	"fmt"
	"pq/manager"
	"pq/models"
	"pq/repository"
)

func NewUserService() UserService{
	userService := UserService{}
	userService.userManager = &manager.UserManager{}
	return userService;
}
type UserService struct{
	userManager *manager.UserManager
}

func (us UserService) GetCategory(uid int) models.PqTestCategory{
	return us.userManager.GetCategory(uid)
}
func (us  UserService) SetCategory(uid int,cid int)(int64,error){
	return us.userManager.UpdateCategory(uid,cid)
}
func (us UserService) SetCity(uid int,area_code string) {

}
func (us UserService) SetArea(uid int,areaCode string)(int64,error){
	// 如果areaCode最后两位不为00,则替换为00
	// 兼容: 因前端只能获取到区一级的城市编码，需要替换成上一级
	cityCode := areaCode[:4]
	cityCode = fmt.Sprintf("%s00000000",cityCode)
	return us.userManager.UpdateArea(uid,cityCode)
}
func (us  UserService) GetUserById(uid int)(repository.UserInfo,error){
	user := repository.UserRepository{}
	return user.GetUser(uid)
}

func (us  UserService) GetUserByPhone(phone string)(repository.UserUnSafeInfo,error){
	user := repository.UserRepository{}
	return user.GetUserByPhone(phone)
}